home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / mac_printing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  4.1 KB  |  137 lines  |  [TEXT/R*ch]

  1. /* Code adapted from Tech Note 95. */
  2.  
  3.  
  4. /* NOTE: Apple reserves the top half of the screen (where the current DITL
  5.     items are located). Applications may use the bottom half of the screen
  6.     to add items, but should not change any items in the top half of the
  7.     screen.  An application should expand the print dialogs only as much
  8.     as is absolutely necessary.
  9. */
  10.  
  11. /* Note: A global search and replace of 'Job' with 'Stl' will produce 
  12.     code that modifies the style dialogs */
  13.  
  14. #include <PrintTraps.h>
  15.  
  16. #include "mac_printing.h"
  17. #define PRJOB_DITL_ID        2323
  18. #define EDIT_ITEM        2    /* Second new dialog item is editable text. */
  19. #define    JobDlgID        -8191    /* resource ID of 'Job' or 'Print' DLOG, DITL, & hdlg         */
  20. #define Myhdlg             8191    /* resource ID of my hdlg to be spliced on to job/stl dialog */
  21.  
  22. extern int    g_printer_dpi;        /* dpi set in mac-specific */
  23. extern THPrint    g_print_rec_h;    /* initialized in mac-specific */
  24.  
  25. Boolean    get_bool_resource( char *rsrc_name ); /* declared in mac-specific */
  26. void Append2hdlg( short srcResID, short dstResID );
  27.  
  28. static TPPrDlg PrtJobDialog;        /* pointer to job dialog */
  29.  
  30. /*    This points to the following structure:
  31.     
  32.       struct { 
  33.           DialogRecord    Dlg;          (The Dialog window)
  34.           ProcPtr        pFltrProc;    (The Filter Proc.)
  35.           ProcPtr        pItemProc;    (The Item evaluating proc. --                             we'll change this)
  36.           THPrint        hPrintUsr;    (The user's print record.)
  37.           Boolean        fDoIt;    
  38.           Boolean        fDone;    
  39.               (Four longs -- reserved by Apple Computer)
  40.           long            lUser1;         
  41.           long            lUser2;        
  42.           long            lUser3;    
  43.           long            lUser4;        
  44.    } TPrDlg; *TPPrDlg;          
  45. */
  46.  
  47.  
  48.  
  49. /*    Declare â€˜pascal’ functions and procedures */
  50. pascal TPPrDlg MyJobDlgInit(THPrint hp);    /* Our extention to PrJobInit */
  51. pascal void MyJobItems(TPPrDlg d, short item); /* Our modal item handler */
  52.  
  53. long prFirstItem;                /* save our first item here */
  54. long prPItemProc;            /* we need to store the old itemProc here */
  55.  
  56. /*-----------------------------------------------------------------------*/
  57.  
  58. OSErr Special_job_dialog( THPrint hPrintRec )
  59. /* Input: a handle to a print record, already allocated and modified.
  60.    Output:  a string containing the "other commands" and an error code. 
  61. */
  62. {
  63.     PrValidate(hPrintRec);
  64.     if (PrError() != noErr)
  65.         return PrError();        
  66.  
  67.     /* call PrJobInit to get pointer to the invisible job dialog */
  68.     PrtJobDialog = PrJobInit(hPrintRec);
  69.     if (PrError() != noErr)
  70.         return PrError();        
  71.  
  72.     Append2hdlg(Myhdlg, JobDlgID);
  73.  
  74.     if (!PrDlgMain(hPrintRec, &MyJobDlgInit))    /* this line does all the 
  75.     stuff */
  76.         return Cancel;
  77.  
  78.     if (PrError() != noErr)
  79.         return PrError();        
  80.     else
  81.         return( noErr );
  82. /* that's all for now */
  83.         
  84. } /* Special_job_dialog */
  85.  
  86. /*------------------------------------------------------------------------*/
  87.  
  88. pascal TPPrDlg MyJobDlgInit (hPrint)
  89. THPrint hPrint;
  90. /* this routine appends items to the standard job dialog and sets up the
  91.     user fields of the printing dialog record TPRDlg 
  92.     This routine will be called by PrDlgMain */
  93. {
  94.     short        firstItem;        /* first new item number */
  95.         
  96.     firstItem = AppendDITL ((DialogPtr)PrtJobDialog,
  97.         PRJOB_DITL_ID); /*call routine to do this */
  98.     
  99.     prFirstItem = firstItem; /* save this so MyJobItems can find it */
  100.     
  101. /* Now comes the part where we patch in our item handler.  We have to save
  102.     the old item handler address, so we can call it if one of the standard items is hit, and put our item handler's address
  103.     in pItemProc field of the TPrDlg struct
  104. */
  105.  
  106.     prPItemProc = (long)PrtJobDialog->pItemProc;
  107.     
  108. /* Now we'll tell the modal item handler where our routine is */
  109.     PrtJobDialog->pItemProc = (ProcPtr)&MyJobItems;
  110.  
  111.     
  112. /* PrDlgMain expects a pointer to the modified dialog to be returned.... */
  113.     return PrtJobDialog;
  114.     
  115. } /*myJobDlgInit*/
  116.  
  117.  
  118. /*-----------------------------------------------------------------------*/
  119.  
  120. /* here's the analogue to the SF dialog hook */
  121.  
  122. pascal void MyJobItems(TPPrDlg theDialog, short itemNo)
  123. {    
  124.     short        itemType;        /* needed for GetDItem/SetDItem call */
  125.     Handle        itemH;
  126.     Rect        itemBox;
  127.     
  128.     if (itemNo == 1) /* OK */
  129.     {
  130.         GetDItem( (DialogPtr)theDialog, EDIT_ITEM + prFirstItem - 1,
  131.             &itemType, &itemH, &itemBox );
  132.         GetIText( itemH, g_other_commands );
  133.     }
  134.     CallPascal( theDialog, itemNo, prPItemProc );
  135. } /* MyJobItems */
  136.  
  137.